/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */

#include "sum_custom_tiling.h"
#include "tiling/tiling_api.h"
#include <vector>

namespace {
constexpr uint32_t PADDING_BYTE = 32U;
}

void GenerateTilingData(uint8_t *tilingBuf, const uint32_t M, const uint32_t N) {
    uint32_t minValue = 0;
    uint32_t maxValue = 0;

    AscendC::GetSumMaxMinTmpSize(N, sizeof(uint32_t), false, maxValue, minValue);

    SumCustomTilingData *tiling = reinterpret_cast<SumCustomTilingData *>(tilingBuf);

    auto paddingFunc = [](const uint32_t n, const uint32_t typeSize) -> uint32_t {
        if (typeSize == 0) {
            return 0;
        }
        return (n * typeSize + PADDING_BYTE - 1U) / PADDING_BYTE * PADDING_BYTE / typeSize;
    };

    tiling->outter = M;
    tiling->inner = paddingFunc(N, sizeof(uint32_t));
    tiling->n = N;
    tiling->tmpBufSize = minValue;

    tiling->out_inner = paddingFunc(M, sizeof(uint32_t));
}